package com.nbcb.fund.service.impl;

import com.nbcb.fund.dao.ChinamutualFundNavDao;
import com.nbcb.fund.entity.po.ChinamutualFundNavPo;
import com.nbcb.fund.service.ChinamutualFundNavService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ChinamutualFundNavServiceImpl implements ChinamutualFundNavService {

    @Resource
    ChinamutualFundNavDao chinamutualFundNavDao;


    @Override
    public ChinamutualFundNavPo getOneByWindCode(String fInfoWindcode) {
        ChinamutualFundNavPo chinamutualFundNavPo = chinamutualFundNavDao.getOneByWindCode(fInfoWindcode);
        return chinamutualFundNavPo;
    }

    @Override
    public List<ChinamutualFundNavPo> listByHistoryNav(String fInfoWindcode) {
        List<ChinamutualFundNavPo> chinamutualFundNavPo = chinamutualFundNavDao.listByWindCode(fInfoWindcode);
        return chinamutualFundNavPo;
    }

    @Override
    public double getZhangDieFuByWindCode(String fInfoWindcode) {
        List<ChinamutualFundNavPo> chinamutualFundNavPo = chinamutualFundNavDao.listTwoByWindCode(fInfoWindcode);
        int size = chinamutualFundNavPo.size();
        if (size < 2) {
            return 0L;
        } else {
            // 最新的净值信息
            ChinamutualFundNavPo chinamutualFundNavPo1 = chinamutualFundNavPo.get(0);
            // 倒数第二新的净值信息
            ChinamutualFundNavPo chinamutualFundNavPo2 = chinamutualFundNavPo.get(1);
            // 净值涨的金额
            long l = chinamutualFundNavPo1.getFNavAccumulated() - chinamutualFundNavPo2.getFNavAccumulated();
            // 净值的涨幅，在昨天的基础上
            long l1 = l / chinamutualFundNavPo2.getFNavAccumulated();
            return l1;
        }
    }
}
